#!/bin/bash

ensure_vars() {
  if [ -z "$ZMICRO_CONFIG_PATH" ]; then
    ZMICRO_CONFIG_PATH=$ZMICRO_HOME/config
  fi
  if [ -z "$ZMICRO_CORE_PATH" ]; then
    ZMICRO_CORE_PATH=$ZMICRO_HOME/core
  fi
  if [ -z "$ZMICRO_PLUGINS_PATH" ]; then
    ZMICRO_PLUGINS_PATH=$ZMICRO_HOME/plugins
  fi
}


env() {
  ensure_vars

  # Load Base Config
  . $ZMICRO_CONFIG_PATH/config

  # Load Doreamon Fns
  . $ZMICRO_CORE_PATH/load
  # . $CURRENT_DIR/load

  # 配置加载顺序
  # 1. mod
  config::load_core_mod
  # 2. Load Config config/*
  load_config $ZMICRO_CONFIG_PATH
  # 3. Load User Config .zmicrorc
  [[ -f $ZMICRO_RC ]] && load_config $ZMICRO_RC

  # Do for mac os
  if [ "$(os::is_macos)" = "true" ]; then
    export ZMICRO_APP_LOGS_PATH=$HOME/.local/zmicro/logs
    export ZMICRO_APP_DATA_PATH=$HOME/.local/zmicro/data
  fi
}

env
